<template>
  <form class="todo-form" @submit.prevent="addTask">
    <input 
      v-model="newTask" 
      type="text" 
      placeholder="输入新的待办事项" 
      @keyup.enter="addTask"
    />
    <button type="submit">添加</button>
  </form>
</template>

<script setup>
import { ref, defineEmits } from 'vue'

const newTask = ref('')
const emits = defineEmits(['add-task'])

const addTask = () => {
  if (newTask.value.trim()) {
    emits('add-task', newTask.value.trim())
    newTask.value = ''
  }
}
</script>

<style scoped>
.todo-form {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>